package com.example.starter.config;

import com.example.starter.service.AnimalService;
import com.example.starter.service.impl.CatServiceImpl;
import com.example.starter.service.impl.DogServiceImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zcs
 * @since 2023/3/23
 */

@Configuration
@EnableConfigurationProperties(AnimalProperties.class)
public class AnimalAutoConfig {

    private final AnimalProperties animalProperties;

    public AnimalAutoConfig(AnimalProperties animalProperties) {
        this.animalProperties = animalProperties;
    }

    @Bean
    public AnimalService demoService(){
        switch (animalProperties.getName()){
            case "cat":
                return new CatServiceImpl();
            case "dog":
                return new DogServiceImpl();
            default:
                return null;
        }
    }

}
